package leetcode_901_1000;

import node.TreeNode;

public class LeeCode_968 {
    public static void main(String[] args) {
        System.out.println(minCameraCover(new TreeNode(0, new TreeNode(0, new TreeNode(0), new TreeNode(0)), null)));
    }
    private static int minCameraCover(TreeNode root) {
        int[] ans = new int[1];
        int r = f(root, ans);
        if (r == 0)
            ans[0]++;
        return ans[0];
    }
    //0:隐藏 1:安装 2:可观
    private static int f(TreeNode node, int[] ans){
        if (node == null)
            return 2;
        int l = f(node.left, ans);
        int r = f(node.right, ans);
        if (l == 0 || r == 0){
            ans[0]++;
            return 1;
        }else if (l == 2 && r == 2){
            return 0;
        }else {
            return 2;
        }
    }
}